package cn.kailangtu.serialport;

public class ReceiveData {
    private byte[] data;
    private byte[] frameId;
    private boolean isStandard;



    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }

    public byte[] getFrameId() {
        return frameId;
    }

    public void setFrameId(byte[] frameId) {
        this.frameId = frameId;
    }

    public boolean isStandard() {
        return isStandard;
    }

    public void setStandard(boolean standard) {
        isStandard = standard;
    }

    public static ReceiveData build(byte[] source)
    {
        ReceiveData result = new ReceiveData();
        byte[] add = new byte[4];
        for(int i = 0;i<4;i++)
        {
            add[i] = source[i+2];
        }
        result.setFrameId(add);

        if(((source[1] >> 7) &0x01) == 0x01 )
        {
            result.setStandard(false);
        }
        else{
            result.setStandard(true);
        }

        int length = source.length -8;

        byte[] data = new byte[length];

        for(int i = 0;i< length;i++){
            data[i] = source[i+6];
        }
        result.setData(data);

        return result;

    }

    public String toString(){
        return "帧ID:"+ CommonUtils.ByteArrayToHexString(frameId)+"\r\n"
                +"数据:"+ CommonUtils.ByteArrayToHexString(data)+"\r\n"
                +"是否标准帧："+(isStandard ? "标准帧":"扩展帧");
    }
}
